package com.scan;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author rkc
 * @date 2022/8/29 15:42
 */
public class JavaFileScanner {

    private String path;
    private List<File> javaFiles = new ArrayList<>();

    /**
     * 传入项目路径
     * @param path
     */
    public JavaFileScanner(String path) {
        this.path = path;
        scan(new File(path + File.separator + "src"));
    }

    private void scan(File f) {
        if (f.isFile()) {
            javaFiles.add(f);
            return;
        }
        File[] fs = f.listFiles();
        if (fs != null && fs.length != 0) {
            for (File item : fs) {
                scan(item);
            }
        }
    }

    public List<File> getJavaFiles() {
        return javaFiles;
    }
}
